﻿#region Vương văn hùng
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data.SqlClient;
using System.Data;
using System.Collections;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;

using DataAccess;
using Entities;
using Common;


namespace BusinessLogic
{
    static class KhachHangTraLaiBanLe
    {
        public static Entities.KhachHangTraLaiBanLe[] SelectKhachHangTraLaiBanLe(Entities.KhachHangTraLaiBanLe hoadon)
        {
            Entities.KhachHangTraLaiBanLe[] list = null;
            try
            {
                SqlConnection cn = DataAccess.Connection.OpenConnection();
                SqlCommand cmd = new SqlCommand("", cn);
                cmd.Parameters.Add(Common.Constants.KhachHangTraLaiBanLe.HanhDong, SqlDbType.NVarChar).Value = hoadon.HanhDong;
                cmd.Parameters.Add(Common.Constants.KhachHangTraLaiBanLe.MaKhachHangTraLaiBanLe, SqlDbType.VarChar).Value = hoadon.MaKhachHangTraLaiBanLe;
                cmd.Parameters.Add(Common.Constants.KhachHangTraLaiBanLe.MaKho, SqlDbType.VarChar).Value = hoadon.MaKho;
                SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                ArrayList arr = new ArrayList();
                while (dr.Read())
                {
                    Entities.KhachHangTraLaiBanLe row = new Entities.KhachHangTraLaiBanLe();
                    arr.Add(row);
                }
                int n = arr.Count;
                if (n == 0)
                {
                    list = null;
                }
                else
                {
                    list = new Entities.KhachHangTraLaiBanLe[n];
                    for (int i = 0; i < n; i++)
                    {
                        list[i] = (Entities.KhachHangTraLaiBanLe)arr[i];
                    }
                }
                cmd.Connection.Dispose();
                cn.Close();
                DataAccess.Connection.CloseConnection();
            }
            catch (Exception ex)
            {
                string s = ex.Message.ToString();
                list = null;
            }
            return list;
        }

        public static int InsertUpdateKhachHangTraLaiBanLe(Entities.KhachHangTraLaiBanLe hoadon)
        {
            int rt = 0;
            try
            {
                SqlConnection cn = DataAccess.Connection.OpenConnection();
                SqlCommand cmd = new SqlCommand("", cn);
                rt = cmd.ExecuteNonQuery();
                cmd.Connection.Dispose();
                cn.Close();
                DataAccess.Connection.CloseConnection();
            }
            catch (Exception ex)
            {
                string s = ex.Message.ToString();
                rt = 0;
            }
            return rt;
        }
    }
}
#endregion
